import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


public class Permutations {

  private int gcd(int a,int b){
     if(b==0) return a;
     return gcd(b,a%b);
  }

  private void run() throws Exception {
      BufferedReader bf = new BufferedReader( new 
                              InputStreamReader(System.in));

      int n = Integer.parseInt(bf.readLine());
      int ax [] = new int [n+1];
      boolean dx [] = new boolean [n+1];

      for(int i=1;i<=n;++i) dx[i] = false;
      
      StringTokenizer st = new StringTokenizer(bf.readLine());
      for(int i=1;i<=n;++i) ax[i] = Integer.parseInt(st.nextToken());
               
      int ans = 1;
      for(int i=1;i<=n;++i) if(dx[i]==false){
           int x = i; int ct = 0; 
           while(dx[x]==false){
                dx[x] = true; x = ax[x]; ++ct;
           }
           ans = ans*ct/gcd(ct,ans);
      }
      System.out.println(ans);
 
  }
  public static void main ( String [] Args ) throws Exception {
     new Permutations().run();
  }
}
